var crypto = require('crypto'), path = require('path'), fs = require('fs');

exports.md5 = function(str, encoding) {
	return crypto.createHash('md5').update(str).digest(encoding || 'hex');
};

exports.createHmac = function(str, key) {
	return crypto.createHmac('md5',key).update(str).digest('hex');
};

exports.zwmd5 = function(data) {
	var Buffer = require("buffer").Buffer;
    var buf = new Buffer(data);
    var str = buf.toString("binary");
    var crypto = require("crypto");
    return crypto.createHash("md5").update(str).digest("hex");
};


exports.sha1 = function(str, encoding) {
	return crypto.createHash('sha1').update(str).digest(encoding || 'hex');
};
function getRandomInt(min, max) {
	  return Math.floor(Math.random() * (max - min + 1)) + min;
	}

exports.sha1 = function(str, encoding) {
	return crypto.createHash('sha1').update(str).digest(encoding || 'hex');
};


exports.weeken = function(week) {
	switch(week)
	{
	case 'Monday':
	  return "周一";
	  break;
	case 'Tuesday':
	  return "周二";
	  break;
	case 'Wednesday':
	  return "周三";
	  break;
	case 'Thursday':
	  return "周四";
	  break;
	case 'Friday':
	  return "周五";
	  break;
	case 'Saturday':
	  return "周六";
	  break;
	case 'Sunday':
	  return "周日";
	  break;
	default:
	  return 'invalid'
	}
};

exports.formatMD = function(MD) {
	var c=MD.substring(0,1);
	if(c==0){
		return MD.substring(1,2);
	}else{
		return MD;
	}
	
};

